//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbTDHocVan
    {
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTDHocVan_SelectAll", null);
            return all;
        }
        public static DataTable SelectAll1()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTDHocVan_SelectAll1", null);
            return all;
        }
        public static DataTable SelectTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTDHocVan_SelectTop", pr);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbTDHocVan OTbTDHocVan)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenTDHocVan", OTbTDHocVan.TenTDHocVan);
            pr[1] = new SqlParameter(@"TrangThai", OTbTDHocVan.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbTDHocVan_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbTDHocVan OTbTDHocVan)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaTDHocVan", OTbTDHocVan.MaTDHocVan);
            pr[1] = new SqlParameter(@"TenTDHocVan", OTbTDHocVan.TenTDHocVan);
            pr[2] = new SqlParameter(@"TrangThai", OTbTDHocVan.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbTDHocVan_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(int MaTDHocVan)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaTDHocVan",MaTDHocVan);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbTDHocVan_Delete", pr);
        }
//-----------------------------------------------------------//
 //       -----------------------------------------------------------//
        public static DataTable SearchTDHocVan(ETbTDHocVan TDHocVan)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenTDHocVan", TDHocVan.TenTDHocVan);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTDHocVan_Search", pr);
            return all;
        }
        //-----------------------------------------------------------//
        public static bool KiemTraDuLieu_Sua(ETbTDHocVan TDHocVan)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenTDHocVan", TDHocVan.TenTDHocVan);
            pr[1] = new SqlParameter(@"MaTDHocVan", TDHocVan.MaTDHocVan);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTDHocVan_KiemTraDuLieu_Sua", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
//-----------------------------------------------------------//
        public static bool KiemTraDuLieu(ETbTDHocVan TDHocVan)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenTDHocVan", TDHocVan.TenTDHocVan);
           
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTDHocVan_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
//-----------------------------------------------------------//

        public static ETbTDHocVan SelectByID(int MaTDHocVan)
        {
            ETbTDHocVan OTbTDHocVan = new ETbTDHocVan();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaTDHocVan",MaTDHocVan);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbTDHocVan_SelectByID", pr);
            if (idr.Read())
              OTbTDHocVan = GetOneTbTDHocVan(idr);
            idr.Close();
            idr.Dispose();
            return OTbTDHocVan;
        }
//-----------------------------------------------------------//
        private static ETbTDHocVan GetOneTbTDHocVan(IDataReader idr)
       {
            ETbTDHocVan OTbTDHocVan = new ETbTDHocVan();
                if (idr["MaTDHocVan"] != DBNull.Value)
                    OTbTDHocVan.MaTDHocVan = (int)idr["MaTDHocVan"];
                if (idr["TenTDHocVan"] != DBNull.Value)
                    OTbTDHocVan.TenTDHocVan = (string)idr["TenTDHocVan"];
                if (idr["TrangThai"] != DBNull.Value)
                    OTbTDHocVan.TrangThai = (int)idr["TrangThai"];
            return OTbTDHocVan;
       }
//-----------------------------------------------------------//
        public static bool TestByID(int MaTDHocVan)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaTDHocVan",MaTDHocVan);
            pr[1] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbTDHocVan_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbTDHocVan> ListAll()
        {
            List<ETbTDHocVan> list = new List<ETbTDHocVan>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbTDHocVan_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbTDHocVan(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }

        public static List<ETbTDHocVan> ListTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            List<ETbTDHocVan> list = new List<ETbTDHocVan>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbTDHocVan_SelectAll", pr);
            while (idr.Read())
              list.Add(GetOneTbTDHocVan(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}